package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetManyidu;
import com.example.yiwei.crm.entity.ManyiduEntity;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;

import static com.example.yiwei.crm.R.id.myd_add_jz_left;


public class JYDetailedSHActivity extends AppCompatActivity {
private TextView txt_manager,txt_customer_name,txt_age,txt_gender,txt_phone,txt_dy_time,txt_yb_number,txt_mxb,
        txt_ly_left,txt_ly_right,txt_jz_left,txt_jz_right,txt_bz,txt_jz_doctor,txt_reason,txt_jz_qk,
        txt_jz_hospital,txt_jd,txt_add_manyidu_time,txt_pj;
    ManyiduEntity manyiduEntity;
    private ImageView img_search,img_luru,img_me,img_tj,img_back,img_commit;
    SharedPreferences sp;
    private Button btn_yes,btn_no;
    int manyidu_id;
    String boolen;
    private TextView txt_luru,txt_cx;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jydetailed_sh);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        txt_luru= (TextView) findViewById(R.id.item_textview_lr);
        txt_cx= (TextView) findViewById(R.id.item_textview_cx);
        txt_add_manyidu_time= (TextView) findViewById(R.id.myd_add_manyidu_add_time);
        txt_pj= (TextView) findViewById(R.id.myd_add_pj);
        btn_no= (Button) findViewById(R.id.jy_detailed_sh_btn_no);
        btn_yes= (Button) findViewById(R.id.jy_detailed_sh_btn_yes);
        img_back= (ImageView) findViewById(R.id.myd_add_img_back);
        img_search= (ImageView) findViewById(R.id.item_image_cx);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        txt_manager= (TextView) findViewById(R.id.myd_add_manger_tv);
        txt_customer_name= (TextView) findViewById(R.id.myd_add_name);
        txt_gender= (TextView) findViewById(R.id.myd_add_sex);
        txt_phone= (TextView) findViewById(R.id.myd_add_phone);
        txt_dy_time= (TextView) findViewById(R.id.myd_add_ly_time);
        txt_yb_number= (TextView) findViewById(R.id.myd_add_yb_number);
        txt_mxb= (TextView) findViewById(R.id.myd_add_mxb);
        txt_ly_left= (TextView) findViewById(R.id.myd_add_ly_left);
        txt_ly_right= (TextView) findViewById(R.id.myd_add_ly_right);
        txt_jz_left= (TextView) findViewById(myd_add_jz_left);
        txt_jz_right= (TextView) findViewById(R.id.myd_add_jz_right);
        txt_bz= (TextView) findViewById(R.id.myd_add_bz);
        txt_jz_doctor= (TextView) findViewById(R.id.myd_add_ys_tv);
        txt_reason= (TextView) findViewById(R.id.myd_add_reason);
        txt_jz_qk= (TextView) findViewById(R.id.myd_add_jzqk_tv);
        txt_jz_hospital= (TextView) findViewById(R.id.myd_add_jzyy_tv);
        txt_jd= (TextView) findViewById(R.id.myd_add_jdr_tv);
        txt_age= (TextView) findViewById(R.id.myd_add_age);
        if ("k6".equals(getIntent().getStringExtra("tag6"))){
            img_luru.setImageResource(R.drawable.gongzuotai);
            txt_luru.setTextColor(Color.rgb(167,167,167));
            img_search.setImageResource(R.drawable.find2);
            txt_cx.setTextColor(Color.rgb(110,184,239));
        }
        manyiduEntity= GetManyidu.get();
        manyidu_id=manyiduEntity.getMyd_id();
        txt_manager.setText(manyiduEntity.getManager_name());
        txt_customer_name.setText(manyiduEntity.getName());
        txt_age.setText(manyiduEntity.getAge()+"");
        if (manyiduEntity.getSex()==1){
            txt_gender.setText("男");
        }else if (manyiduEntity.getSex()==2){
            txt_gender.setText("女");
        }
        txt_phone.setText(manyiduEntity.getPhone());
        txt_dy_time.setText(manyiduEntity.getHospital_time());
        txt_yb_number.setText(manyiduEntity.getYb());
        txt_mxb.setText(manyiduEntity.getMxb());
        if (manyiduEntity.getAly_left()==null||manyiduEntity.getAly_left().equals("")){
            txt_ly_left.setText(manyiduEntity.getLy_left());
        }else{
            txt_ly_left.setText(manyiduEntity.getLy_left()+"("+manyiduEntity.getAly_left()+")");
        }
        if (manyiduEntity.getAly_right()==null||manyiduEntity.getAly_right().equals("")){
            txt_ly_right.setText(manyiduEntity.getLy_right());
        }else{
            txt_ly_right.setText(manyiduEntity.getLy_right()+"("+manyiduEntity.getAly_right()+")");
        }
        if (manyiduEntity.getAjz_left()==null||manyiduEntity.getAjz_left().equals("")){
            txt_jz_left.setText(manyiduEntity.getJz_left());
        }else{
            txt_jz_left.setText(manyiduEntity.getJz_left()+"("+manyiduEntity.getAjz_left()+")");
        }

        if (manyiduEntity.getAjz_right()==null||manyiduEntity.getAjz_right().equals("")){
            txt_jz_right.setText(manyiduEntity.getJz_right());
        }else{
            txt_jz_right.setText(manyiduEntity.getJz_right()+"("+manyiduEntity.getAjz_right()+")");
        }
        txt_bz.setText(manyiduEntity.getBZ());
        txt_jz_doctor.setText(manyiduEntity.getDoctor_name());
        txt_jz_qk.setText(manyiduEntity.getState());
        txt_reason.setText(manyiduEntity.getResult());
        txt_jz_hospital.setText(manyiduEntity.getHospital());
        txt_jd.setText(manyiduEntity.getJdr());
        txt_pj.setText(manyiduEntity.getPj());
        txt_add_manyidu_time.setText(manyiduEntity.getAdd_manyidu_time());
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        img_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedSHActivity.this,JDcoorActivity.class);
                intent.putExtra("ii","ii");
                startActivity(intent);
                finish();
            }
        });
        img_luru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedSHActivity.this,JDcoorActivity.class);
                startActivity(intent);
                finish();
            }
        });
        img_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedSHActivity.this,JDcoorActivity.class);
                intent.putExtra("me","me");
                startActivity(intent);
                finish();
            }
        });
        img_tj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYDetailedSHActivity.this,JDcoorActivity.class);
                intent.putExtra("tt","tt");
                startActivity(intent);
                finish();
            }
        });
 btn_yes.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
         new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc = new SC();
                JSONObject object =sc.storage(sp);
                try {
                    object.put("KMA19",1);
                    object.put("addoredit","edit");
                    object.put("KMA01",manyidu_id);
                    object.put("KAA01",manyiduEntity.getCustomer_id());
                    object.put("KAA02",manyiduEntity.getName());
                    object.put("KAA39",manyiduEntity.getJdr_id());
                    object.put("KAA40",manyiduEntity.getJdr());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String json=object.toString();
                String result= NetWorkUtils.getCount(baseClass.edit_sh_state_url,json);
                try {
                    JSONObject jsonObject=new JSONObject(result);
                    boolen=jsonObject.getString("ifsuccess");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if ("true".equals(boolen)){
                                Toast.makeText(JYDetailedSHActivity.this, "审核成功", Toast.LENGTH_SHORT).show();
                                finish();
                            }
                        }
                    });

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
});
        btn_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SC sc = new SC();
                        JSONObject object =sc.storage(sp);
                        try {
                            object.put("KMA19",2);
                            object.put("addoredit","edit");
                            object.put("KMA01",manyidu_id);
                            object.put("KAA01",manyiduEntity.getCustomer_id());
                            object.put("KAA02",manyiduEntity.getName());
                            object.put("KAA39",manyiduEntity.getJdr_id());
                            object.put("KAA40",manyiduEntity.getJdr());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        String json=object.toString();
                        String result= NetWorkUtils.getCount(baseClass.edit_sh_state_url,json);
                        try {
                            JSONObject jsonObject=new JSONObject(result);
                            boolen=jsonObject.getString("ifsuccess");
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if ("true".equals(boolen)){
                                        Toast.makeText(JYDetailedSHActivity.this, "审核成功", Toast.LENGTH_SHORT).show();
                                        finish();
                                    }
                                }
                            });

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        });


    }
}
